package com.pda.xinma.presenter;

import com.pda.xinma.bean.LatheMachinBean;
import com.pda.xinma.bean.ScanResultBean;
import com.pda.xinma.bean.UserBean;
import com.pda.xinma.bean.request.AgvMoveRequest;
import com.pda.xinma.bean.request.QRcodeRequest;
import com.pda.xinma.contract.AgvMoveContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class AgvMovePresenter extends BasePresenter<AgvMoveContract.View> implements AgvMoveContract.Presenter {
    @Override
    public void scanTheQRCodeToVerify(String code) {
        QRcodeRequest request = new QRcodeRequest();
        request.setQRCode(code);
        NetUtils.geApi().scanTheQRCodeToVerify(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ScanResultBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ScanResultBean> scanResultBeanBaseAppEntity) throws Exception {
                        getView().setScanBean(scanResultBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getLatheList() {
        NetUtils.geApi().getLatheList()
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<LatheMachinBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<LatheMachinBean>> listBaseAppEntity) throws Exception {
                        getView().setList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void confirmCarry(AgvMoveRequest request) {
        NetUtils.geApi().confirmCarry(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<Object>>() {
                    @Override
                    public void accept(BaseAppEntity<Object> userBeanBaseAppEntity) throws Exception {
                        getView().showMessage(userBeanBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
